package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.AdChannelDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.pojos.wemedia.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 */
@RestController
@Api(tags = "频道管理")
@Slf4j
@RequestMapping("/api/v1/channel")
public class


WmChannelController{

    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 加载所有频道
     *
     * @return
     */
    @GetMapping("/list")
    public ResponseResult channels() {
        log.info("加载所有频道");
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }

    /**
     * 添加频道
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannelDto adChannelDto) {
        log.info("添加频道:{}", adChannelDto);
        return wmChannelService.saveChannel(adChannelDto);
    }

    /**
     * 分页查询频道列表
     *
     * @param adChannelDto
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody AdChannelDto adChannelDto) {
        log.info("分页查询频道列表:{}", adChannelDto);
        return wmChannelService.pageList(adChannelDto);
    }

    /**
     * 删除频道
     */
    @GetMapping("del/{id}")
    public ResponseResult delChannel(@PathVariable("id") Integer id){
        log.info("删除频道:{}", id);
        return wmChannelService.delChannel(id);
    }

    /**
     * 修改频道
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannelDto adChannelDto) {
        log.info("修改频道:{}", adChannelDto);
        return wmChannelService.updateChannel(adChannelDto);
    }


}
